package com.xinggq.pay.api.feign;

import com.xinggq.common.CommonResult;
import com.xinggq.common.enums.ResponseEnum;
import com.xinggq.pay.api.dto.YseCommonPayPespDTO;
import com.xinggq.pay.api.dto.YseCommonPayReqDTO;
import com.xinggq.pay.api.dto.YseCommonRefundReqDTO;
import com.xinggq.pay.api.dto.YseCommonRefundRespDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * YsePayServiceClient降级处理类
 * @author xinggq
 * @since 2025-01-20
 */
@Component
@Slf4j
public class YsePayServiceClientFallback implements YsePayServiceClient {

  @Override
  public CommonResult<YseCommonPayPespDTO<?>> pay(YseCommonPayReqDTO yseCommonPayReqDTO) {
    log.error("统一支付服务调用失败，触发降级处理，订单号：{}",
        yseCommonPayReqDTO != null ? yseCommonPayReqDTO.getMerchantOutTradeNo() : "unknown");
    return CommonResult.fail(ResponseEnum.UNKNOWN_ERROR);
  }

  @Override
  public String payCallback(String ysePayNotifyStr) {
    log.error("支付回调失败，触发降级处理");
    return "fail";
  }

  @Override
  public String refundCallback(String yseRefundNotifyStr) {
    log.error("退款回调失败，触发降级处理");
    return "fail";
  }

  @Override
  public CommonResult<YseCommonRefundRespDTO> refund(YseCommonRefundReqDTO refundDTO) {
    log.error("退款失败，触发降级处理，订单号：{}",
        refundDTO != null ? refundDTO.getMerchantOutTradeNo() : "unknown");
    return CommonResult.fail(ResponseEnum.UNKNOWN_ERROR);
  }
}